package com.zyl.Ecs.auth.web.controller;

import com.zyl.Ecs.common.domain.auth.vo.PermissionVO;
import com.zyl.Ecs.auth.service.PermissionService;
import com.zyl.Ecs.common.response.Result;
import com.zyl.Ecs.common.response.ResultCode;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @version v1.0
 * @ProjectName: Ecs
 * @Package: com.zyl.Ecs.auth.web.controller
 * @ClassName: PermissionController
 * @Description TODO (权限控制层)
 * @Author 翟玉龙
 * @Date 2024/12/4-19:42
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/permission")
public class PermissionController {

    private final PermissionService permissionService;

    /**
     * 查询权限列表
     *
     * @return {@link Result }<{@link ? }>
     */
    @GetMapping
    public Result<?> list() {
        return Result.success(Optional.ofNullable(permissionService.getList())
                .map(list -> list.stream()
                        .map(PermissionVO::toVO)
                        .collect(Collectors.toList()))
                .orElse(null))
                .apply(ResultCode.SUCCESS.getMessage());
    }
}
